import { runCommand } from ".";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        runCommand(context, options, isUndo, (sheet, options) => {
            const { col, colCount = 1 } = options;
            sheet.addColumns(col, colCount);
            const tables = sheet.tables.all();
            for(let i = 0 ; i < tables.length ; i++) {
                const table = tables[i];
                if(table.name().startsWith('custom')) {
                    const {row:tableRow, rowCount: tRowCount, col:tableCol, colCount:tColCount} = table.dataRange();
                    if(col >= tableCol && col <= tableCol + tColCount) {
                        for(let r = tableRow ; r < tableRow + tRowCount ; r++) {
                            const orgCell = sheet.getCell(r, col + colCount);
                            // const backColor = orgCell.backColor();
                            // //backgroundImageLayout: cell.backgroundImageLayout(),
                            // const borderBottom = orgCell.borderBottom();
                            // const borderLeft = orgCell.borderLeft();
                            // const borderRight = orgCell.borderRight();
                            // const borderTop = orgCell.borderTop();
                            for(let c = col ; c < col + colCount ; c++) {
                                const nCell = sheet.getCell(r, c);
                                nCell.backColor(orgCell.backColor());
                                nCell.borderBottom(orgCell.borderBottom());
                                nCell.borderLeft(orgCell.borderLeft());
                                nCell.borderRight(orgCell.borderRight());
                                nCell.borderTop(orgCell.borderTop());
                            }
                        }
                    }
                }
            }
        })
    }
};
